//
// Created by baka on 2025/10/19.
//

#ifndef ZHJS_HTTP_PACKET_H
#define ZHJS_HTTP_PACKET_H


#include <stdint.h>



//method宏定义
#define HTTP_METHOD_GET "GET "
#define HTTP_METHOD_POST "POST "

//header相关字段宏定义
#define HTTP_STRING_HOST "Host"

//一些固定的字符串
#define HTTP_URL "www.myweb.com"


//枚举器 : header索引
typedef enum
{
    content_type = 0,
    Content_Length,
    connection,
    headers_member_index_max,
} Headers_member_index_t;


typedef struct line_member_attr
{
    const char *value;
    uint32_t length;
} line_member_attr_t;


typedef struct header_member_attr
{
    const char *name;
    const char *value;
    uint32_t length;
} header_member_attr_t;



struct http_packet;
typedef  void(*callback)(struct http_packet *packet);
typedef struct http_packet
{
    line_member_attr_t lines[3];
    header_member_attr_t headers[headers_member_index_max];
    char *http_packet_lines;
    char *http_packet_line_param;
    char *http_packet_headers;
    char *http_packet_body;
    char *http_packet;
    uint32_t http_packet_length;
    uint32_t http_lines_length;
    uint32_t http_headers_length;
    uint32_t http_body_length;
    uint32_t bytes_read;
    callback callback_function;
    struct {
        uint8_t parse_state;  // 0=未解析 1=解析中 2=解析完成
        uint8_t error_code;   // 错误码
        uint16_t parsed_len;  // 已解析长度
    } parse;

}http_packet_t;



void http_packet_init(http_packet_t *packet);









#endif //ZHJS_HTTP_PACKET_H